<!-- 发票详情 -->
<template>
  <view>
    <navBar v-if="isShowCustomNavBar" :navbarData.sync="navbarData"></navBar>
    <toptitle :title="taskStatus[invoiceDetail.taskStatus]" :textArr="['尊贵的麦卡伦贵宾，您的发票申请已提交','确认收货后我们会尽快为您开具']"/>
    <view class="view_box">
      <view class="line">
        <text>发票抬头</text>
        <text class="fontNumber">{{ invoiceDetail.invoiceTitle }}</text>
      </view>
      <view class="line">
        <text>发票税号</text>
        <text class="fontNumber">{{ invoiceDetail.payeeRegisterNo }}</text>
      </view>
      <view class="line">
        <text>发票金额</text>
        <text class="fontNumber"> <text class="mark">¥</text>{{invoiceDetail.invoiceAmount }}</text>
      </view>
      <view class="line">
        <text>开票时间</text>
        <text class="fontNumber">{{ invoiceDetail.createTime }}</text>
      </view>
      <view class="line">
        <text>邮箱地址</text>
        <text class="fontNumber">{{ invoiceDetail.email }}</text>
      </view>
      <view class="button_tohome" @click="handleToHomePage">前往首页</view>
    </view>
		<!-- 弱提示 弹窗 -->
		<toast-popup ref="toastPopup" @onToastPopupClick="onToastPopupClick"></toast-popup>
  </view>
</template>

<script>
import tip from '@/utils/tip';
import api from '@/api/api';
import customize from '@/utils/customize';
import Loading from '@/components/common/loading';
import NavBar from '@/components/common/navbar';
import { SYSTEM_INFO, CUSTOMER_INFO, MERCHANT_INFO, USER_SPECICAL_INFO } from '@/utils/constant';
import toptitle from './components/toptitle';
export default {
  components: {
    navBar:NavBar,
    toptitle: toptitle
  },
  data() {
    return {
      isShowCustomNavBar: true,
      // 组件所需的参数
      navbarData: {
        showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
        navbarTitle: '发票信息', //导航栏 中间的标题
        hideSearch:true,
        hideHome:true
      },
      orderId: '',
      taskSn: '',
      invoiceDetail: [],
      taskStatus: {
        0: '未提交',
        1: '提交失败',
        2: '提交成功',
        3: '提交成功',    //处理中
        4: '开票失败',
        5: '开具成功'  //开票成功
      },
      previousPages: '',
      nowPages:''
    };
  },
  onLoad(option) {
    let that = this;
    that.orderId = option.orderNo;
    that.taskSn = option.tasksn;
    let pages = getCurrentPages();
    let prevpage = pages[pages.length - 2];
    let currPage = pages[pages.length - 1];
    this.nowPages = currPage.route;
    if (prevpage == undefined) {
      this.previousPages = '';
    } else {
      this.previousPages = prevpage.route ? prevpage.route : '';
    }
    that.getInvoiceDetial();
  },
  onShow() {
    getApp().cl_tracker.track('mini_program_view', { path:  this.nowPages, pageName: '发票详情'})
  },
  methods: {
		/**
		 * 展示弱提示
		 * @param {Object} msg 文案
		 */
		handleShowTextToast(msg){
			try{
				this.$refs.toastPopup.showToast(msg);
			}catch(e){}
		},
		/**
		 * 若提示按钮点击回调
		 * @param {Object} data.type 类型：confirm确定，cancel取消
		 * @param {Object} data.callBackData 呼气弹窗时传入的数据
		 */
		onToastPopupClick(data){},
    getInvoiceDetial: async function() {
      let that = this;
      let customerInfo = uni.getStorageSync(CUSTOMER_INFO);
      let invoiceList = await api.getInvoiceDetail(
        {
          method: 'POST',
          header: {
            jwt: customerInfo.jwt
          }
        },
        this.orderId,
        this.taskSn
      );
      if (invoiceList.code == 1000) {
        that.invoiceDetail = invoiceList.data;
        var s_createTime = that.invoiceDetail.createTime;
        that.invoiceDetail.createTime = s_createTime.substr(0, 10);
      } else {
        that.handleShowTextToast(invoiceList.msg);
      }
    },
    // 跳转首页
    handleToHomePage(){
      uni.reLaunch({
        url: '/pages/home/home'
      });
    },
  }
};
</script>

<style>
.pageTitle {
  text-align: center;
  border-bottom: 1px solid #7f7f7f;
  margin: 0 40rpx;
  padding: 40rpx 0 80rpx 0;
  font-size: 34rpx;
  font-family: syMEDIUM;
  color: #000;
}
.view_box{
  margin: 0 48rpx;
  padding-bottom: 50rpx;
  font-family: FrankNew-Regular,NotoSansSC-Regular;
}
.line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 144rpx;
  line-height: 144rpx;
  border-bottom: 1px solid #F2F2F2;
  font-size: 28rpx;
  color: #000;
}
.line .fontNumber {
  font-size: 24rpx;
  color: #757575;
}
.mark{
  font-family: NotoSansSC-Regular;
}
.button_tohome {
  width: 100%;
  text-align: center;
  height: 80rpx;
  line-height: 80rpx;
  border-radius: 48rpx 16rpx 48rpx 48rpx;
  box-sizing: content-box;
  background-color: #000;
  color: #fff;
  margin-top: 76rpx;
  font-size: 28rpx;
  font-weight: 500;
}
</style>
